package com.news.cloud.web.model;

import com.news.cloud.jpa.domain.Feed;

import javax.persistence.Transient;
import java.text.SimpleDateFormat;
import java.util.Locale;

/**
 * Created by hiephn on 2014/08/28.
 */
public class FeedResponse extends NameDescResponse<Feed> {

    private static final SimpleDateFormat sdf = new SimpleDateFormat("EEEE, dd/MM/yyyy", new Locale("vi", "vn"));

    private String pubDate;
    private String lastUpdate;
    private String link;
    private String imgUrl;
    private String author;
    private int minRead;
    private int hot;
    private int likeNo;
    private int shareNo;
    private int commentNo;
    private int channelId;
    private int providerId;

    // these 2 attributes are omitted to save bandwidth
    @Transient
    private String channel;
    @Transient
    private String provider;

    // used for sorting one time only
    private int weight = -1;

    @Override
    public void setData(Feed entity) {
        super.setData(entity);
        this.pubDate = sdf.format(entity.getPubDate());
        this.lastUpdate = sdf.format(entity.getLastUpdate());
        this.link = entity.getLink();
        this.imgUrl = entity.getImgUrl();
        this.author = entity.getAuthor();
        this.minRead = entity.getMinRead();
        this.hot = entity.getHot();
        this.likeNo = entity.getLikeNo();
        this.shareNo = entity.getShareNo();
        this.commentNo = entity.getCommentNo();
        this.weight = entity.getWeight();
        this.channel = entity.getChannel().getName();
        this.provider = entity.getProvider().getName();
        this.channelId = entity.getChannel().getId();
        this.providerId = entity.getProvider().getId();
    }

    public String getPubDate() {
        return pubDate;
    }

    public void setPubDate(String pubDate) {
        this.pubDate = pubDate;
    }

    public String getLastUpdate() {
        return lastUpdate;
    }

    public void setLastUpdate(String lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public String getImgUrl() {
        return imgUrl;
    }

    public void setImgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public int getMinRead() {
        return minRead;
    }

    public void setMinRead(int minRead) {
        this.minRead = minRead;
    }

    public int getHot() {
        return hot;
    }

    public void setHot(int hot) {
        this.hot = hot;
    }

    public int getLikeNo() {
        return likeNo;
    }

    public void setLikeNo(int likeNo) {
        this.likeNo = likeNo;
    }

    public int getShareNo() {
        return shareNo;
    }

    public void setShareNo(int shareNo) {
        this.shareNo = shareNo;
    }

    public int getCommentNo() {
        return commentNo;
    }

    public void setCommentNo(int commentNo) {
        this.commentNo = commentNo;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public String getProvider() {
        return provider;
    }

    public void setProvider(String provider) {
        this.provider = provider;
    }

    public int getChannelId() {
        return channelId;
    }

    public void setChannelId(int channelId) {
        this.channelId = channelId;
    }

    public int getProviderId() {
        return providerId;
    }

    public void setProviderId(int providerId) {
        this.providerId = providerId;
    }
}
